package com.zb.service.impl;

import com.zb.dto.DeviceDTO;
import com.zb.es.EsRepository;
import com.zb.service.DeviceService;
import com.zb.vo.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DeviceServiceImpl implements DeviceService {

    @Autowired
    private EsRepository esRepository;

    @Override
    public boolean setStatus(String deviceId, Boolean status) {
        return esRepository.updateStatus(deviceId, status);
    }

    @Override
    public boolean updateDeviceTag(String deviceId, String tag) {
        DeviceDTO deviceDTO = esRepository.searchDeviceById(deviceId);
        if (deviceDTO == null) return false;
        esRepository.updateDeviceTag(deviceId, tag);
        return true;
    }

    @Override
    public Pager<DeviceDTO> searchDevice(Long page, Long pageSize, String deviceId, String tag, Integer status) {
        return esRepository.searchDevice(page, pageSize, deviceId, tag, status);
    }
}
